package com.example.anxiang.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;

import com.example.anxiang.R;
import com.example.anxiang.activity.api.Api;
import com.example.anxiang.activity.api.ApiConfig;
import com.example.anxiang.activity.api.MsgCallback;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.zhpan.bannerview.BannerViewPager;

import java.util.ArrayList;
import java.util.List;

import Banner.BannerAdaper;
import Banner.BannerData;
import Nav_Bottom.HomeFragment;
import Nav_Bottom.SearchFragment;
import Nav_Bottom.SettingFragment;

/**
 * The type Main activity.
 */
public class MainActivity extends AppCompatActivity {

    private BottomNavigationView bottomNavigationView;
    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d("oncreate", "begin");
        setContentView(R.layout.activity_main);
        NavBottom();//底部导航栏

    }
    private void NavBottom(){
            bottomNavigationView = findViewById(R.id.nav_bottom);
            bottomNavigationView.setSelectedItemId(R.id.nav_home);
            ReplaceFragment(new HomeFragment());
            bottomNavigationView.setOnItemSelectedListener(item -> {
                switch (item.getItemId()){
                    case R.id.nav_home:
                        ReplaceFragment(new HomeFragment());
                        return true;

                    case R.id.nav_search:
                        ReplaceFragment(new SearchFragment());
                        return true;
                    case R.id.nav_setting:
                        ReplaceFragment(new SettingFragment());
                        return true;
                }

                return false;
            });
        }
    private void ReplaceFragment(Fragment fragment) {
        getSupportFragmentManager()
                .beginTransaction()
                .replace(R.id.fragmentlayout,fragment)
                .commit();
    }



}